package com.wss.day08.Test2;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/4/29
 */
public class RemoveDuplicates {
    public static void main(String[] args) {
        List<String> stringList = new ArrayList<>();
        stringList.add("apple");
        stringList.add("banana");
        stringList.add("apple");
        stringList.add("cherry");

        List<String> uniqueStringList = removeDuplicates(stringList);
        System.out.println("去除重复后的字符串列表: " + uniqueStringList);


        List<Person> personList = new ArrayList<>();
        personList.add(new Person("Alice", 20));
        personList.add(new Person("Bob", 25));
        personList.add(new Person("Alice", 20));
        personList.add(new Person("Charlie", 30));

        List<Person> uniquePersonList = removeDuplicates(personList);
        System.out.println("去除重复后的 Person 对象列表: " + uniquePersonList);
    }

    public static <T> List<T> removeDuplicates(List<T> list) {
        Set<T> set = new HashSet<>(list);
        return new ArrayList<>(set);
    }
}
